<!-- 会员, 查看自己的全部健康档案记录 -->
<template>
	<view>
		<cu-custom bgColor="bg-E96141" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">我的处方列表</block>
		</cu-custom>
		<!-- 会员信息 -->
		<view class="member-info" :style="{position:headerPosition}">
			<view class="list-item">
				<text class="pure-text">
					会员姓名：{{memberInfo.realname}}{{memberInfo.sex=='1'?' [男]':''}}{{memberInfo.sex=='2'?' [女]':''}}
				</text>
			</view>
			<view class="list-item">
				<!-- <button class="cu-btn bg-cyan round sm btn-1" @tap="reloadData()">
					<text class="title">刷新页面</text>
				</button> -->
				<button class="cu-btn bg-cyan round sm btn-1" @tap="toYiHuPage()">
					<text class="title">回到医护</text>
				</button>
			</view>
			<view class="list-item">
				<text class="pure-text">
					会员账号：{{phone}}
				</text>
			</view>
			<view class="list-item">
				<button class="cu-btn bg-cyan round sm btn-2" @tap="addData()">
					<text class="title">新增档案</text>
				</button>
			</view>
		</view>
		
		
		
		<!-- 分页数据 -->
		<view class="no-data-con"
			v-if="!pageDataList || pageDataList.length==0">
			<image src="https://ylb123.oss-cn-hangzhou.aliyuncs.com/app/empty.png"></image>
			<view class="title">您还没有处方列表~</view>
		</view>
		<view class="page-list-con"
			v-if="pageDataList && pageDataList.length>0">
			<view
				v-for="(item, index) in pageDataList" :key="item.id"
				class="one-row">
				<view class="left-con">
					<view class="day-con">{{item.day}}</view>
					<view class="year-month-con">{{item.yearMonth}}</view>
					<view class="opers">
						<button class="cu-btn bg-cyan round sm btn-1" @tap="toDetailPage(item)">
							<text class="title">处方详情</text>
						</button>
					</view>
				</view>
				<view class="right-con">
					<view class="title">
						<text class="account">
							[医生] {{item.doctor}}
						</text>
						<text class="name">
							[护士] {{item.nurse}}
						</text>
					</view>
					<view class="list-value">
						电话：{{item.phone?item.phone:'暂无记录'}} 
					</view>
					<view class="list-value">
						姓名：{{item.name?item.name:'暂无记录'}} 
					</view>
					<view class="list-value">
						性别：{{item.sex?item.sex:'暂无记录'}}
					</view>
					<view class="list-value">
						年龄：{{item.age?item.age:'暂无记录'}} 
					</view>
					<view class="list-value">
						日期：{{item.createTime?item.createTime:'暂无记录'}} 
					</view>
					<view class="list-value">
						诊断：{{item.zhend?item.zhend:'暂无记录'}} 
					</view>
				</view>
			</view>
		</view>
		<uni-load-more 
			v-if="pageDataList && pageDataList.length>0"
			:status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import {
		USER_HAS_LOGIN,
	} from "@/common/util/constants"
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	import moment from 'moment'
	
	export default {
		name: "chufang-list",
		components: {
			uniLoadMore	
		},
		props:{
			pageCur: String ,
		},
		data() {
			return {				
				headerPosition:"fixed",
				memberInfo: {
					id: '',
					phone: '',
					realname: '',
					sex: '',
					birthday: '',
					address: '',
				},
				cateMaskState: 0, //分类面板展开状态
				headerPosition:"fixed",
				headerTop:"0px",
				loadingType: 'more', //加载更多状态
				filterIndex: 0, 
				pageDataList: [
					
				],
				
				keyword: '',
				currPageNo: 1,
				totalPageNo: 1,
				pageSize: 10,
				phone: '',
			}
		},
		created() {
			this.validUserInfo()
			this.loadData()
			// console.info(this.$route)
		},
		onLoad(options) {
			var phone=options.phone;
			console.log(options);
			this.phone=phone;
			this.memberInfo.id = options.memId?options.memId:''
			this.memberInfo.phone = options.memPhone?options.memPhone:''
			this.memberInfo.realname = options.memRealname?options.memRealname:''
			this.memberInfo.sex = options.memSex?options.memSex:''
			this.memberInfo.birthday = options.memBirthday?options.memBirthday:''
			this.memberInfo.address = options.memAddress?options.memAddress:''
		},
		methods: {
			// 用户信息
			validUserInfo(){
				this.userHasLogin = uni.getStorageSync(USER_HAS_LOGIN)
				if(this.userHasLogin!='1'){
					this.$tip.toast('登录超时');
					let app_must_permission_status = uni.getStorageSync('APP_MUST_PERMISSION_STATUS')
					uni.clearStorageSync();
					uni.setStorageSync('APP_MUST_PERMISSION_STATUS', app_must_permission_status)
					setTimeout(function() {
						uni.redirectTo({
						    url: '/pages/login/login'
						});
					}, 500);
					return false
				}
			},
			//代该会员-添加处方信息
			addData(){
				let _params = '?nouse=1' + 
					'&memId=' + this.memberInfo.id + 
					'&type=1' +  
					'&memPhone=' + this.memberInfo.phone + 
					'&memRealname=' + this.memberInfo.realname + 
					'&memSex=' + this.memberInfo.sex + 
					'&memBirthday=' + this.memberInfo.birthday + 
					'&memAddress=' + this.memberInfo.address + 
					'&jkdaId='
				//redirectTo 不会压栈
				//navigateTo 会压栈
				uni.navigateTo({
					url: '/pages/chufang/chufangdetail' + _params
				})
			},
			//查看详情
			toDetailPage(item){
				if(!item.id){
					this.$tip.toast('数据错误')
					return false
				}
				let _params = '?nouse=1' +
					'&id=' + item.id + 
					'&createDate=' + item.createTimeShort + '&type=2' + '&phone=' + item.phone + '&name=' + item.name + '&sex=' + item.sex + '&age=' + item.age + '&createTime=' + item.createTime + '&zhend=' + item.zhend + '&image=' + item.image 
				uni.navigateTo({
					// url: '/pages/member-health-record/detail' + _params
					url: '/pages/chufang/chufangdetail' + _params
				})
			},
			onPageScroll(e){
				//兼容iOS端下拉时顶部漂移
				if(e.scrollTop>=0){
					this.headerPosition = "fixed";
				}else{
					this.headerPosition = "absolute";
				}
			},
			//下拉刷新
			onPullDownRefresh(){
				this.loadData('refresh');
			},
			//加载更多
			onReachBottom(){
				this.loadData();
			},
			//分页加载 ，带下拉刷新和上滑加载
			async loadData(type='add', loading) {
				let that = this
				//没有更多直接返回
				if(type === 'add'){
					if(that.loadingType === 'nomore'){
						return;
					}
					that.loadingType = 'loading';
				}else if(type === 'refresh'){
					that.pageDataList = []
					that.currPageNo = 1
				}else{
					that.loadingType = 'more'
				}
				if(that.currPageNo>that.totalPageNo){
					that.loadingType = 'nomore'
					if(loading == 1){
						uni.hideLoading()
					}else{
						uni.stopPullDownRefresh();
					}
					return false
				}
				
				let _pageParams = {
					pageNo: that.currPageNo,
					pageSize: that.pageSize,
					keyword: that.keyword,
					phone: that.phone,
					
				}
				// let list = await that.$http.get('/health/jkda/listformem', {params:_pageParams})
				let list = await that.$http.get('/chufangmanager/chufang/queryByToken', {params:_pageParams})
					.then(res => {
						if(res.data.success){
							//uni.hideLoading()
							let jsonData = res.data.result
							
							if(!jsonData){
								return []
							}
							that.totalPageNo = jsonData.pages
							let _list = jsonData.records?jsonData.records:[]
							if(_list && _list.length>0){
								let _item = {}
								for(let i=0;i<_list.length;i++){
									_item = _list[i]
									_item.createTimeShort = moment(_item.createTime).format('YYYY-M-D')
									_item.day = moment(_item.createTime).format('D')
									_item.yearMonth = moment(_item.createTime).format('YYYY年M月')
								}
							}
							return _list
						}else{
							//uni.hideLoading()
						}
					}).catch(err => {
						//uni.hideLoading()
						return []
					});
				
				if(list && list.length>0){
					list.forEach(item=>{
						that.pageDataList.push(item)
					})
				}
				
				//判断是否还有下一页，有是more  没有是nomore
				that.loadingType  = (that.currPageNo >= that.totalPageNo)?'nomore':'more'
				if(type === 'refresh'){
					if(loading == 1){
						uni.hideLoading()
					}else{
						uni.stopPullDownRefresh();
					}
				}
				
				if(that.currPageNo<that.totalPageNo){
					that.currPageNo++
				}
			},
			stopPrevent(){
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* 会员信息 */
	.member-info{
		width: 100%;
		position: fixed;
		z-index: 10;
		left: 0;
		// #ifdef APP-PLUS
		top: 78px;
		// #endif
		background-color: #ffffff;
		height: 100px;
		overflow: hidden;
		padding: 20px;
		border: 0px solid #f00;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		.list-item{
			float:left;
			width: 50%;
			margin-bottom: 10px;
			.pure-text{
				height: 30px;
				line-height: 30px;
			}
			.btn-1{
				float: right;
				background-color: #1CBBB4;
				height: 30px;
				line-height: 30px;
			}
			.btn-2{
				float: right;
				background-color: #ff9800;
				height: 30px;
				line-height: 30px;
			}
		}
	}
	
	/* 分页列表 */
	.space-line{
		width: 100%;
		height: 180px;
	}
	.no-data-con{
		text-align: center;
		padding: 30% 0 0 0;
		image{
			width: 150px !important;
			height: 150px !important;
		}
		.title{
			color: #aaaaaa;
		}
	}
	.page-list-con{
		margin-top: 190upx;
		padding: 20upx;
		color: #999999;
		.one-row{
			width: 100%;
			height: 360upx;
			overflow: hidden;
			background-color: #FFFFFF;
			margin-bottom: 20upx;
			padding: 20upx;
			border-radius: 10upx;
			border: 1px solid #ececec;
			.left-con{
				width: 30%;
				float: left;
				text-align: center;
				border-right: 1px dashed #cccccc;
				.day-con{
					font-size: 80upx;
					font-weight: bold;
				}
				.year-month-con{
					font-size: 32upx;
					margin-bottom: 10upx;
				}
				.opers{
					font-size: 48upx;
					text{
						font-size: 24upx;
					}
					.btn-1{
						width: 85%;
						background-color: #ff9270;
						height: 56upx;
						line-height: 56upx;
						margin-bottom: 10upx;
					}
				}
			}
			.right-con{
				width: 68%;
				float: right;
				border: 0px solid #f00;
				height: 360upx;
				overflow: hidden;
				.title{
					font-size: 26upx;
					font-weight: bold;
					margin-bottom: 10upx;
					height: 50upx;
					line-height: 50upx;
					.account{
						margin-right: 10upx;
						color: #1CBBB4;
					}
					.name{
						float: right;
						color: #EA6040;
					}
				}
				.list-value{
					margin-bottom: 5upx;
				}
			}
		}
		
	}
	

</style>
